import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import {App, fetchApp} from './App';
import ErrorPage from './views/error/index';
import {Home, fetchHome} from './views/home/index';
import Test from './views/test/index';
import Detail from './views/detail/index';
import SearchComponent from './views/search';
import About from './views/about/index';
import Shop from './views/shop/index';
import reportWebVitals from './reportWebVitals';
import { createBrowserRouter, RouterProvider } from 'react-router-dom';

const router = createBrowserRouter([
    {
        path: '/',
        element: <App />,
        errorElement: <ErrorPage />,
        loader: fetchApp,
        children: [
            {
                path: 'home',
                loader: fetchHome,
                element: <Home />
            },
        ]
    },
    {
        path: 'detail',
        element: <Detail />,
    },
    {
        path: 'test/:id',
        element: <Test />
    },
    {
        path: 'search',
        element: <SearchComponent />,
    },
    {
        path: 'about/:name',
        element: <About />
    },
    {
        path: 'shop',
        element: <Shop />,
    } 
])

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
    <RouterProvider router={router}></RouterProvider>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
